package com.v1.lo;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.orm.ibatis.SqlMapClientTemplate;
import org.springframework.stereotype.Service;

/**
 * @author luyang
 * @create_time 2009/03/23
 */
@Service("BaseLO")
public class BaseLO {
	protected final Log log = LogFactory.getLog(getClass());

	@Resource(name = "sqlMapClientTemplate")
	protected SqlMapClientTemplate sqlMapClient;

	@SuppressWarnings("unchecked")
	public <E> List<E> queryForList(E model, Statement statement) {
		return sqlMapClient.queryForList(statement.toString(), model);
	}

	@SuppressWarnings("unchecked")
	public <E, T> List<T> queryForList(E model, Statement statement, T clazz) {
		return sqlMapClient.queryForList(statement.toString(), model);
	}

	public int update(Object model, Statement statement) {
		return sqlMapClient.update(statement.toString(), model);
	}

	public Object insert(Object model, Statement statement) {
		return sqlMapClient.insert(statement.toString(), model);
	}

	@SuppressWarnings("unchecked")
	public <E> E queryForObject(E model, Statement statement) {
		return (E) sqlMapClient.queryForObject(statement.toString(), model);
	}

	public int queryForCount(Object model, Statement statement) {
		return (Integer) sqlMapClient.queryForObject(statement.toString(), model);
	}

	@SuppressWarnings("unchecked")
	public Map<String, Object> queryForMap(Object model, Statement statement, String keyProperty,
			String valueProperty) {
		return (Map<String, Object>) sqlMapClient.queryForMap(statement.toString(), model, keyProperty,
				valueProperty);
	}
}
